<!DOCTYPE html>
<html>

<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <title>Hi，慧林淘友注册登录</title>
  <link rel="stylesheet" href="layui/css/layui.css">
</head>

<body>
  <!-- code -->
  <div class="layui-container">
    <div class="layui-row">
      <div class="layui-col-xs12 layui-col-sm6 layui-col-md4 layui-col-lg4 layui-col-xs-offset0  layui-col-sm-offset3  layui-col-md-offset4  layui-col-lg-offset4">
        <h1>同步授权中心</h1>
      </div>
    </div>
    <div class="layui-row">
      <div class="layui-col-xs12 layui-col-sm6 layui-col-md4 layui-col-lg4 layui-col-xs-offset0  layui-col-sm-offset3  layui-col-md-offset4  layui-col-lg-offset4">
        <hr class="layui-bg-red">
        <form class="layui-form  layui-form-pane">
          <div class="layui-form-item">
            <label class="layui-form-label">账号</label>
            <div class="layui-input-inline">
              <input type="text" name="username" required lay-verify="required|phone|number" placeholder="请输入账号（手机号）" autocomplete="off"
                class="layui-input">
            </div>
          </div>
          <div class="layui-form-item">
            <label class="layui-form-label">密码</label>
            <div class="layui-input-inline">
              <input type="password" name="password" required lay-verify="required" placeholder="请输入密码" autocomplete="off"
                class="layui-input">
            </div>
          </div>
          <div class="layui-form-item">
              <label class="layui-form-label">邮箱</label>
              <div class="layui-input-inline">
                <input type="text" name="email" required lay-verify="email" placeholder="邮箱" autocomplete="off"
                  class="layui-input">
              </div>
            </div>
          <div class="layui-form-item">
            <div class="layui-input-block">
              <button class="layui-btn" lay-submit lay-filter="login">立即登录</button>
              <a href='' class="layui-btn layui-btn-primary" lay-submit lay-filter="reg">注册账号</a>
            </div>
          </div>
        </form>
        <hr class="layui-bg-green">
      </div>
    </div>
  </div>
  <!-- code -->
  <script src="layui/layui.js"></script>
  <script>
    layui.use(['layer', 'jquery', 'form'], function () {
      var layer = layui.layer,
        $ = layui.jquery,
        form = layui.form;
      form.on('submit(login)', function (data1) {
        //layer.msg(JSON.stringify(data1.field));
        $.ajax({
          //几个参数需要注意一下
          type: "post",//方法类型
          dataType: "text",//预期服务器返回的数据类型
          url: "https://vip.lyhuilin.com/login",//url
          data: {
            mobile: data1.field.username,
            password: data1.field.password,
            email: data1.field.email,
            action: "userlogin",
          },
          success: function (result) {
            console.log(result);//打印服务端返回的数据(调试用)
            if (result.code == 1) {
              layer.msg('登录成功');
            } else {
              layer.msg('登录失败');
            }
            ;
            layer.msg(result);
            layer.open({
              title: '登录状态'
              , content: result
            });
          },
          error: function () {
            alert("异常！");
          }
        });
        return false;
      });
      form.on('submit(reg)', function (data1) {
        //layer.msg(JSON.stringify(data1.field));
        $.ajax({
          //几个参数需要注意一下
          type: "post",//方法类型
          dataType: "text",//预期服务器返回的数据类型
          url: "https://vip.lyhuilin.com/v1/user",//url
          data: {
            mobile: data1.field.username,
            password: data1.field.password,
            email: data1.field.email,
            name: "No10000.",
            action: "adduserinfo",
          },
          success: function (result) {
            console.log(result);//打印服务端返回的数据(调试用)
            if (result.code == 1) {
              layer.msg('注册成功');
            } else {
              layer.msg('注册失败');
            }
            ;
            layer.msg(result);
            layer.open({
              title: '注册状态'
              , content: result
            });
          },
          error: function () {
            alert("异常！");
          }
        });
        return false;
      });
    });
  </script>
</body>

</html>